﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>方向条件-表单字段条件</title>

    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>

    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
     <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>   
     <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <base target="_self" />
    <script type="text/javascript">

        function Esc() {
            if (event.keyCode == 27)
                window.close();
            return true;
        }

        var OperForString = null;
        var OperForNumber = null;

        //初始化页面函数.....
        $(function () {

            //两者都隐藏.
            document.getElementById("TB_Val").style.display = "none";
            document.getElementById("DDL_Val").style.display = "none";

            var condType = GetQueryString("CondType");
            var fk_flow = GetQueryString("FK_Flow");
            var fk_mainNode = GetQueryString("FK_MainNode");
            var fk_Node = GetQueryString("FK_Node");
            var toNodeID = GetQueryString("ToNodeID");

            //求出来 frmID .
           // var flow = new Entity("BP.WF.Flow", fk_flow);

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddUrlData();

            var data = handler.DoMethodReturnString("CondByFrm_Init");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>加载失败:<br>" + data + "</font> .");
                return;
            }

            //转json.
            data = JSON.parse(data);
            var sys_mapattr = data["Sys_MapAttr"];

            //绑定查询.
            GenerBindDDL("DDL_Fields", sys_mapattr, "No", "Name", "all");

            //绑定操作。
            //GenerBindDDL("DDL_Operator", OperForNumber, "No", "Name", "=");
            //document.getElementById("TB_Note").value = data.Note;

            var wf_Conds = data["WF_Conds"];

            //增加处理.
            for (var i = 0; i < wf_Conds.length; i++) {

                var cond = wf_Conds[i];

                var newRow = "";
                newRow = "<tr >";
                newRow += "<td class=Idx>" + i + "</td>";
                newRow += "<td>" + cond.AttrKey + "</td>";
                newRow += "<td>" + cond.AttrName + "</td>";
                newRow += "<td>" + cond.FK_Operator + "</td>";
                newRow += "<td>" + cond.OperatorValue + "</td>";
                newRow += "<td>" + cond.OperatorValueT + "</td>";
                if (cond.CondOrAnd == 0)
                    newRow += "<td> AND </td>";
                else
                    newRow += "<td> OR </td>";

                newRow += "<td>";
                newRow += "<a href=\"javascript:Delete('" + cond.MyPK + "')\"><img src='../../Img/Btn/Delete.gif' border=0 />删除</a>";
                newRow += "</td>";
                newRow += "</tr>";
                $("#Table1 tr:last").after(newRow);
            }

        });

        //执行保存..
        function Save(saveType) {

            var condType = GetQueryString("CondType");
            var fk_flow = GetQueryString("FK_Flow");
            var fk_mainNode = GetQueryString("FK_MainNode");
            var fk_Node = GetQueryString("FK_Node");

            var toNodeID = GetQueryString("ToNodeID");

            var DDL_Fields = $("#DDL_Fields").val(); //  字段.
            var DDL_Operator = $("#DDL_Operator").val(); //  操作符.

            var OperVal = "";

            var tb = document.getElementById("TB_Val");
            var tbText = document.getElementById("TB_Text");
            if (tb.style.display == "" || tbText.style.display == "inline") {
                OperVal = tb.value;
            } else {
                OperVal = $("#DDL_Val").val(); //  操作符.
            }

            
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("DDL_Fields", DDL_Fields);
            handler.AddPara("DDL_Operator", DDL_Operator);
            handler.AddPara("OperVal", OperVal);
            handler.AddPara("OperValText", encodeURI(tbText.value));
            handler.AddPara("SaveType", saveType);

            handler.AddPara("CondType", condType);
            handler.AddPara("FK_Flow", fk_flow);
            handler.AddPara("FK_MainNode", fk_mainNode);
            handler.AddPara("FK_Node", fk_Node);


            var data = handler.DoMethodReturnString("CondByFrm_Save");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                window.location.href = url;
                return;
            }

            // alert(data);
            window.location.href = window.location.href;

            //$("#Msg").html("<font color=green>" + data + "</font>");
        }

        //执行删除..
        function Delete( mypk ) {

            if (window.confirm('您确定要删除吗？') == false)
                return;

            //初始化表格.
            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=CondByFrm_Delete&MyPK=" + mypk + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        $("#Msg").html("<font color=red>" + data + "</font>");
                        return;
                    }

                    if (data.indexOf('url@') == 0) {
                        var url = data.replace('url@', '');
                        window.location.href = url;
                        return;
                    }
                    window.location.href = window.location.href;
                }
            });
        }

        //当字段选择的时候.
        function changeCond(c) {

            if (c == null || c.value.length == 0)
                return;

            var key = c.value;
            if (key == "all")
                return;

            var fk_flow = GetQueryString("FK_Flow");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("FK_Flow", fk_flow);
            handler.AddPara("KeyOfEn", key);

            var data = handler.DoMethodReturnString("CondByFrm_InitField");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                window.location.href = url;
                return;
            }

            data = JSON.parse(data);

            //获得 mapattr.
            var mapattr = data["Sys_MapAttr"][0];
            //操作符.
            var opers = data["Opers"];

            //两者都隐藏.
            document.getElementById("TB_Val").style.display = "none";
            document.getElementById("TB_Text").style.display = "none";
            document.getElementById("DDL_Val").style.display = "none";
            $("#opts").html("");


            if (mapattr.LGType == "1") {
                /*是枚举类型*/
                var enums = data["Enums"];
                GenerBindDDL("DDL_Val", enums, "IntKey", "Lab", 0);

                //显示.
                document.getElementById("DDL_Val").style.display = "";
            }

            if (mapattr.LGType == "2") {
                document.getElementById("TB_Text").style.display = "inline";
                $("#opts").html("<input type='button' onclick=\"javascript:SelectFKData('" + mapattr.MyPK + "');\" value='请选择数据' />");
            }

            if (mapattr.LGType == "0") {
                document.getElementById("TB_Val").style.display = "";
            }

            //绑定操作符.
            GenerBindDDL("DDL_Operator", opers, "No", "Name", "=");
        }
        ///选择外部数据.
        var newWindow = "";
        function SelectFKData(fk_mapAttr) {
            OpenEasyUiDialogExt('CondByFrmSelectFKData.htm?FK_MapAttr=' + fk_mapAttr, '选择一个值', '600', '400', false);
        }
        function getValue(data) {
            $('#eudlg').dialog('close');
            $("#TB_Val").val(data[0]);
            $("#TB_Text").val(data[1]);

        } 
         
    </script>
</head>
<body onkeypress="Esc();">

<form id="cc" > 
<table  style="width:90%;">
<tr>
<td style="width:20%;">选择表单字段: </td>
<td>
<select id="DDL_Fields" name="DDL_Fields" style="width:400px;"  onchange="changeCond(this)" ></select>
 </td>
</tr>

<tr>
<td style="width:20%;">操作符: </td>
<td><select id="DDL_Operator" name="DDL_Operator" style="width:100px;"  ></select> </td>
</tr>

<tr>
<td style="width:20%;">值: </td>
<td>
<input type="text" value="" style="width:100px;" id="TB_Val" name="TB_Val" />
<input type="text" value="" style="width:100px;" id="TB_Text" name="TB_Text" />
<span id="opts"> </span>
<br />
<select id="DDL_Val" name="DDL_Val" style="width:100px;" >  </select>


 </td>
</tr>

<tr>
<td></td>
<td colspan=1> 
<input type="button" value="保存为AND条件" onclick="Save('AND');"  /> 
<input type="button" value="保存为OR条件"  onclick="Save('OR');" /> 
</td>
</tr>
</table>

<table id="Table1" name="Table1"  style="width:90%;">
<tr>
<th>序</th>
<th>字段的英文名</th>
<th>中文名 </th>
<th>操作符</th>
<th>值</th>
<th>标签</th>
<th>运算关系</th>
<th>操作</th>
</tr>
</table>

 
</form>

 <center><div id="Msg" /></center>

</body>
</html>

